var webpack = require('webpack'),
    path    = require('path'),
    HtmlWebpackPlugin = require('html-webpack-plugin'),
    OpenBrowserWebpackPlugin = require('open-browser-webpack-plugin');
var src = path.join(__dirname, 'src');
var publish = path.join(__dirname, 'publish');

var option = {
  entry: {
    app: src,
    vendors: ['react', 'react-dom', 'react-router']
  },
  output: {
    path: publish,
    filename: 'js/[name].js'
  },
  module: {
    perLoaders: [{
      test: /\.jsx?$/,
        include: src,
        loaders: ['jshint-loader']
    }],
    loaders: [{
        test: /\.style$/,
        include: src,
        loaders: ['style']
    }, {
        test: /\.css$/,
        include: src,
        loaders: ['style', 'css']
    }, {
        test: /\.scss$/,
        include: src,
        loaders: ['style', 'css', 'sass']
    }, {
        test: /\.jsx?$/,
        include: src,
        loader: 'babel'
    }, {
        test: /\.(gif|jpg|png)$/,
        include: src,
        loader: 'url-loader',
        query: {
            limit: '50000',
            name: 'img/[name].[ext]'
        }
    }, {
        test: /\.(woff|svg|ttf|eot)([\?]?.*)$/,
        include: src,
        loader: 'url-loader',
        query: {
            limit: '50000',
            name: 'font/[name].[ext]'

        }
    }]
  },
  resolve: {
      extensions: ['', '.js', '.jsx']
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),   // 代码监视
    new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
    new HtmlWebpackPlugin({                 // 自动生成 .html 文件
      title: 'Hello Word',                      // 网页标题
      filename: 'index.html',                   // 指定文件名可加路径
      template: 'src/templates/src/html.ejs',   // 引用模板
      hash : true,                              // 生成hash序列号
      cache: true                               // 内容变化是生成HTML文件
    }),
    new webpack.ProvidePlugin({             // 注册全局变量
      React: "react",
      ReactDOM: "react-dom",
      ReactRouter: "react-router"
    }),
    new OpenBrowserWebpackPlugin()          // 制动打开浏览器
  ],
  jshint: {                                 // 开启 es6 语法验证
    esnext: true
  },
  devtool: 'eval-source-map'
}
module.exports = option;
